#!/bin/bash

# 配置变量
MYSQL_SERVER='node04'
OPENTSDB_SERVER='node02:14242'
HAZELCAST_GROUP='mango-lanniao'
ZOO_SERVER='node01 node02 node03'
KAFKA_SERVER='node01 node02 node03'

# 获取参数
get_var(){
    SERVICE=$1
    SERVICE_PORT=$2
    hostaddr=
    for node in $SERVICE; do
        hostaddr="$hostaddr $node:$SERVICE_PORT"
    done
}

# 获取 mysql 默认配置
GET_MYSQL_SERVER=$(cat application.properties.default | grep jdbc:mysql | awk -F '[//|/]' '{print $3}')

# 拼接 kafka 参数
get_var "$KAFKA_SERVER" "9092"
KAFKA_LIST=$(echo $hostaddr |sed 's# #,#g')

# 拼接zookeeper 参数
get_var "$ZOO_SERVER" "2181"
ZOOK_LIST=$(echo $hostaddr |sed 's# #,#g')

sed \
  -e "s#${GET_MYSQL_SERVER}#${MYSQL_SERVER}:3306#" \
  -e "s#kafka.url=.*#kafka.url=$KAFKA_LIST#" \
  -e "s#zookeeper.url=.*#zookeeper.url=$ZOOK_LIST#" \
    application.properties.default > application.properties